home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / pascal / tptc17tc.zip / LINKLIST.PAS < prev    next >
Pascal/Delphi Source File  |  1988-03-25  |  2KB  |  61 lines

  1.  
  2. (*
  3.  * Example of pointer manipulation with circular type declarations
  4.  *
  5.  *)
  6.  
  7. program Linked_List_Example;
  8.  
  9. type 
  10.      Next_Pointer = ^Full_Name;
  11.  
  12.      Full_Name = record
  13.        First_Name : string[12];
  14.        Initial    : char;
  15.        Last_Name  : string[15];
  16.        Next       : Next_Pointer;
  17.      end;
  18.  
  19. var  
  20.      Start_Of_List : Next_Pointer;
  21.      Place_In_List : Next_Pointer;
  22.      Temp_Place    : Next_Pointer;
  23.      Index         : integer;
  24.  
  25. begin  (* main program *)
  26.                        (* generate the first name in the list *)
  27.    New(Place_In_List);
  28.    Start_Of_List := Place_In_List;
  29.    Place_In_List^.First_Name := 'John';
  30.    Place_In_List^.Initial := 'Q';
  31.    Place_In_List^.Last_Name := 'Doe';
  32.    Place_In_List^.Next := nil;
  33.                        (* generate another name in the list *)
  34.    Temp_Place := Place_In_List;
  35.    New(Place_In_List);
  36.    Temp_Place^.Next := Place_In_List;
  37.    Place_In_List^.First_Name := 'Mary';
  38.    Place_In_List^.Initial := 'R';
  39.    Place_In_List^.Last_Name := 'Johnson';
  40.    Place_In_List^.Next := nil;
  41.                   (* add 10 more names to complete the list *)
  42.    for Index := 1 to 10 do begin
  43.       Temp_Place := Place_In_List;
  44.       New(Place_In_List);
  45.       Temp_Place^.Next := Place_In_List;
  46.       Place_In_List^.First_Name := 'William';
  47.       Place_In_List^.Initial := 'S';
  48.       Place_In_List^.Last_Name := 'Jones';
  49.       Place_In_List^.Next := nil;
  50.    end;
  51.                    (* display the list on the video monitor *)
  52.    Place_In_List := Start_Of_List;
  53.    repeat
  54.       Write(Place_In_List^.First_Name);
  55.       Write(' ',Place_In_List^.Initial);
  56.       Writeln(' ',Place_In_List^.Last_Name);
  57.       Temp_Place := Place_In_List;
  58.       Place_In_List := Place_In_List^.Next;
  59.    until Temp_Place^.Next = nil;
  60. end.  (* of main program *)
  61.